﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Entity;
using System.Data;

namespace Core.Dao
{
    class OrderLineDao
    {
        public bool insert(OrderLine orderLine)
        {
            object[,] param = {
                {"@OrderId", orderLine.OrderId},
                {"@ServiceId", orderLine.ServiceId},
                {"@Quanity", orderLine.Quantity},
                {"@Price", orderLine.Price},
                {"@Desc", orderLine.Desc},
            };
            String sql = "insert into ORDER_LINES(ORD_ID, SVC_ID, OLN_QUANTITY, OLN_PRICE, OLN_DESC) " +
                "values(@OrderId, @ServiceId, @Quanity, @Price, @Desc)";
            return DB.exec(sql, param);
        }

        public bool update(OrderLine orderLine)
        {
            object[,] param = {
                {"@OrderId", orderLine.OrderId},
                {"@ServiceId", orderLine.ServiceId},
                {"@Quanity", orderLine.Quantity},
                {"@Price", orderLine.Price},
                {"@Desc", orderLine.Desc},
                {"@id", orderLine.Id},
            };
            String sql = "update ORDER_LINES set ORD_ID = @OrderId, SVC_ID = @ServiceId, OLN_QUANTITY = @Quanity, OLN_PRICE = @Price, OLN_DESC = @Desc " +
                "where OLN_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "delete from ORDER_LINES where OLN_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(String ids)
        {
            object[,] param = {
                {"@ids", ids}   
            };
            String sql = "delete from ORDER_LINES where OLN_ID in (" + ids + ")";
            return DB.exec(sql);
        }

        public DataTable get(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "select * from ORDER_LINES where OLN_ID = @id";
            return DB.getData(sql, param);
        }

        public DataTable getAll()
        {
            String sql = "select * from ORDER_LINES";
            return DB.getData(sql);
        }
    }
}
